package com.masasdani.paypal;

import com.alibaba.fastjson2.JSON;
import com.masasdani.paypal.domain.EventEntity;
import com.masasdani.paypal.domain.SaleEntity;
import com.paypal.api.payments.Event;
import com.paypal.api.payments.Sale;

public class TestMain {

    public static void main(String[] args) {
        String str = "{\"id\":\"WH-46W7619047707654J-1X079291TW228474R\",\"event_version\":\"1.0\",\"create_time\":\"2024-09-10T09:07:07.559Z\",\"resource_type\":\"sale\",\"event_type\":\"PAYMENT.SALE.COMPLETED\",\"summary\":\"Payment completed for $ 2.0 USD\",\"resource\":{\"billing_agreement_id\":\"I-FW9SGHT7TUAH\",\"amount\":{\"total\":\"2.00\",\"currency\":\"USD\",\"details\":{\"subtotal\":\"2.00\"}},\"payment_mode\":\"INSTANT_TRANSFER\",\"update_time\":\"2024-09-10T09:07:02Z\",\"create_time\":\"2024-09-10T09:07:02Z\",\"protection_eligibility_type\":\"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE\",\"transaction_fee\":{\"currency\":\"USD\",\"value\":\"0.37\"},\"protection_eligibility\":\"ELIGIBLE\",\"links\":[{\"method\":\"GET\",\"rel\":\"self\",\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/24727058FJ433020A\"},{\"method\":\"POST\",\"rel\":\"refund\",\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/24727058FJ433020A/refund\"}],\"id\":\"24727058FJ433020A\",\"state\":\"completed\",\"invoice_number\":\"\"},\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-46W7619047707654J-1X079291TW228474R\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-46W7619047707654J-1X079291TW228474R/resend\",\"rel\":\"resend\",\"method\":\"POST\"}]}";
        EventEntity eventEntity = JSON.parseObject(str, EventEntity.class);
        // 支付完成时间
        SaleEntity saleEntity = JSON.parseObject(eventEntity.getResource().toString(), SaleEntity.class);
        String saleId = saleEntity.getId();
        String agreementId = saleEntity.getBilling_agreement_id();
        System.out.println("Sale ID: " + saleId);
        System.out.println("agreement ID: " + agreementId);

    }
}
